package com.xy.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtTest {
    public static void main(String[] args) {
        JwtBuilder builder = Jwts.builder()
                .setId("888")
                .setSubject("xy")
                .setIssuedAt(new Date())
//                .setExpiration(new Date())
                .claim("role", "admin")
                .signWith(SignatureAlgorithm.HS512, "kkb123");
        String token = builder.compact();
        System.out.println(token);
        Claims cliams = Jwts.parser().setSigningKey("kkb123").parseClaimsJws(token).getBody();
        System.out.println(cliams);
    }
}
